package edu.zut.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebServlet(urlPatterns = "/demo4")
public class ServletDemo4 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取web.xml中的初始化参数
        ServletContext context = this.getServletContext();
        String v = context.getInitParameter("key");
        System.out.println("v = " + v);
        //获取资源文件
        InputStream stream = context.getResourceAsStream("db.properties");
        Properties properties = new Properties();
        properties.load(stream);
        String username = properties.getProperty("username");
    }
}